package com.dxf.sysadmin.controller;
import com.dxf.common.utils.ResultJson;
import com.dxf.sysadmin.entity.po.SysRolePo;
import com.dxf.sysadmin.entity.qo.SysRoleQo;
import com.dxf.sysadmin.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/role")
@Api(tags  = "SysRoleController|角色控制器")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    /**
     * @Description: 角色列表分页查询
     */
    @PostMapping("rolePage")
    @PreAuthorize("@el.check('role.detail')")
    @ApiOperation("角色列表分页查询")
    public ResultJson rolePage(@RequestBody SysRoleQo qry){
        return sysRoleService.rolePage(qry);
    }

    /**
     * @Description: 根据id获取角色详情
     */
    @GetMapping("details/{rid}")
    @ApiOperation("根据id获取角色详情")
    public ResultJson details(@PathVariable Long rid){
        return sysRoleService.details(rid);
    }

    /**
     * @Description: 根据SysRolePo对象添加或修改角色及权限
     */
    @PostMapping("saveOrUpdate")
    @ApiOperation("根据SysRolePo对象添加或修改角色及权限")
    public ResultJson saveOrUpdate(@RequestBody SysRolePo po){
        return sysRoleService.saveOrUpdate(po);
    }

    /**
     * @Description: 更具id列表删除角色
     */
    @PostMapping("delete")
    @ApiOperation(value = "更具id列表删除角色")
    public ResultJson deleteUser(@RequestParam("uidList[]") List<Long>  uidList){
        return sysRoleService.deleteUser(uidList);
    }

    /**
     * @Description: 获取角色权限树数据（更具操作选中tree，无操作，无法选中）
     */
    @GetMapping("getRoleTree")
    @ApiOperation(value = "获取角色权限树数据")
    public ResultJson getRoleTree(){
        return sysRoleService.getRoleTree();
    }
}
